from utils.captcha_lib import generate_captcha, CaptchaOutputType
from utils.exception import error_decorator, response, AppStatus
from utils.helper import get_window


class JsApi:
    @classmethod
    @error_decorator("退出APP")
    def close_window(cls, window_id):
        """
        关闭窗口
        :param window_id:
        :return:
        """
        window = get_window(window_id)
        if window:
            window.destroy()

        return response()

    @classmethod
    @error_decorator("最小化窗口")
    def minimize_window(cls, window_id):
        """
        最小化窗口
        :param window_id:
        :return:
        """
        window = get_window(window_id)
        if window:
            window.minimize()

        return response()

    @classmethod
    @error_decorator("获取验证码")
    def captcha(cls):
        return response(data=generate_captcha(output=CaptchaOutputType.base64))
